﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    /// <summary>
    /// 新闻类
    /// </summary>
    public class NewsInfo
    {
        public NewsInfo()
        {
            Title = "";
            NewsContent = "";
            AddTime = "";
            AttachmentList = new List<AttachmentInfo>();

            Creater = "";
            Modifer = "";
        }

        public string NewsID { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string NewsContent { get; set; }

        /// <summary>
        /// 添加时间
        /// </summary>
        public string AddTime { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public string ModifyTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string Creater { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        public string Modifer { get; set; }

        /// <summary>
        /// 是否置顶
        /// </summary>
        public bool IsTop { get; set; }


        /// <summary>
        /// 附件列表
        /// </summary>
        public IList<AttachmentInfo> AttachmentList { get; set; }

        /// <summary>
        /// 浏览次数
        /// </summary>
        public int ViewCount { get; set; }


        /// <summary>
        /// 分组名称
        /// </summary>
        public string NewsGroupName { get; set; }


        public string FirstPageShow 
        {
            get
            {
                if (Title.Length > 12)
                {
                    return Title.Substring(0, 12)+"...";
                }
                else
                {
                    return Title;
                }
            }
        }


        public string AttarchmentString
        {
            get { return ""; }
            set
            {
                AttachmentList.Clear();

                if (!string.IsNullOrEmpty(value))
                {
                    string[] lines = value.Split('|');
                    foreach (var line in lines)
                    {
                        if (line.Length > 0)
                        {
                            string[] _sp = line.Split(':');

                            AttachmentList.Add(new AttachmentInfo { FileName = _sp[0], SaveName = _sp[1] });
                        }
                    }
                }
            }
        }
    }
}
